# Create your views here.
from django.views.decorators.csrf import csrf_exempt

from blog.models import BlogPost
from django.shortcuts import render_to_response
from blog.models import Img


# 用户名qbmzc psd zdh761953

def archive(request):
    posts = BlogPost.objects.all()
    return render_to_response("archive.html", {'posts': posts})


def index(request):
    return render_to_response("index.html")


# 图片上传
@csrf_exempt
def upload_img(request):
    if request.method == 'POST':
        img = Img(img_url=request.FILES.get('img'))
        img.save()
    return render_to_response('imgupload.html')


# 图片展示
def show_img(request):
    imgs = Img.objects.all()
    context = {
        "imgs": imgs
    }
    return render_to_response("showImg.html", context)
